package ba01;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 飞哥
 * @version V1.0
 * @package ba01
 * @date 2021/7/23 10:40
 *
 * beans中的对象在被调用时会全部被创建
 */
public class SpringTest01 {
    @Test
    public void test01(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("ba01/applicationContext.xml");
        //获取student对象
        Student student = (Student) ac.getBean("myStudent");
        System.out.println(student);
    }

    @Test
    public void test02(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("ba01/applicationContext.xml");
        Date myDate = (Date) ac.getBean("myDate");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
        String nowTime = simpleDateFormat.format(myDate);
        System.out.println(nowTime);
    }

    @Test
    public void test03(){
        long millis = System.currentTimeMillis();
        Date date1 = new Date(millis);
        Date date2 = new Date();
        System.out.println(date1);
        System.out.println(date2);
        date2.setTime(millis);
        System.out.println(date2);
    }
}
